package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.BaseContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
     public R<String> submit(@RequestBody Orders orders){
  log.info("用户下单数据—--->：{}",orders.toString());
        orderService.submit(orders);
         return R.success("下单成功");
     }

    /**
     * 订单查询
     * @param page
     * @param pageSize
     * @return
     */

     @GetMapping("/userPage")
     public R<Page> userPage(int page,int pageSize){
        Page userPage = new Page();
         LambdaQueryWrapper<Orders> ordersLambdaQueryWrapper=new LambdaQueryWrapper<>();
         ordersLambdaQueryWrapper.eq(Orders::getUserId, BaseContext.GetCurrentId());
         ordersLambdaQueryWrapper.orderByDesc(Orders::getOrderTime);

         orderService.page(userPage,ordersLambdaQueryWrapper);

        return R.success(userPage);

     }


}
